package com.miaow;

import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

import javax.ws.rs.core.MediaType;


//@FeignClient注解来指定服务提供者的名称  configuration属性指定了一个内部静态类MultipartSupportConfig，用于配置Feign的编码器。
@FeignClient(value = "eureka-feign-upload-server",configuration = FileServiceClient.MultipartSupportConfig.class)
public interface FileServiceClient {

    //SpringFormEncoder是Feign提供的一个编码器，用于处理multipart/form-data类型的请求。
    @PostMapping(value = "/upload",consumes = MediaType.MULTIPART_FORM_DATA)
    String uploadFile(@RequestPart( value = "file") MultipartFile file);


    @Configuration  //代表这个是一个配置类，告诉Spring
    class MultipartSupportConfig{
        @Bean
        public Encoder feignFromEncoder(){
            //返回一个Feign的编码器
            return new SpringFormEncoder();
        }
    }
}
